package main

import (
	"dh.com/store/common/wrapper"
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/registry/etcd"
	"github.com/micro/go-micro/util/log"

	"dh.com/store/api/goods/client"
	"dh.com/store/api/goods/handler"
)

func main() {
	// New Service
	service := micro.NewService(
		micro.Name("com.dh.store.api.goods"),
		micro.Version("latest"),
		micro.Registry(etcd.NewRegistry()),
	)

	// Initialise service
	service.Init(
		// create wrap for the Goods srv client
		micro.WrapHandler(wrapper.LogWrapper),
		micro.WrapHandler(client.GoodsWrapper(service)),
	)

	// Register Handler
	service.Server().Handle(service.Server().NewHandler(handler.NewGoods()))

	// Run service
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
